home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 25
/
Cream of the Crop 25.iso
/
bbs
/
dgwrl201.zip
/
DOG201.RES
/
DOGIGM4.ZIP
/
DWRLDIGM.DOC
< prev
next >
Wrap
Text File
|
1996-11-14
|
7KB
|
183 lines
Generic Data Structure of DogWorld's Note Records.
Your program should be able to add/append this info
to the end of the users note.x file.
Byte Data
Position Type Description
-----------------------------------------------------------------------
1 to 2 int Received Status (always zero for new notes)
3 to 18 char 1st Code [optional] (see MAILCODE.DOC)
19 to 34 char 2nd Code [optional] " "
35 to 50 char 3rd Code [optional] " "
51 to 215 char Title and border of note.
(A (`n) should seperate the title and border.
Place a backquote(`) inside bytes 51 and 52 to
supress the display of the title and prompt.
216 to 715 char Body of the note. Place a backquote(`) inside
bytes 216 and 217 to supress the display of the
body and the (MORE) prompt.
(Total: 715 bytes)
NOTE! - Pascal programmers should define the "C" char strings as an
array of characters for proper translation.
EXAMPLE:
DogNote = Record
Received : Integer; { set this to zero }
Code1 : Array[1..16] Of Char; { 1st mail code }
Code2 : Array[1..16] Of Char; { 2nd mail code }
Code3 : Array[1..16] Of Char; { 3rd mail code }
Title : Array[1..165] Of Char; { Title and border }
Body : Array[1..500] Of Char; { Body of note }
END;
/* C version - Copyright 1996 by Ken Cothran. All rights reserved. */
/* You have my permission to include this code in your own programs. */
/*
/* You can simulate direct access through mail codes by using the */
/* special code (``) double backquote for both the title and body of */
/* the note. When DogWorld processes a note like this, it skips the */
/* display of the title/body and doesn't show the (MORE) prompt. */
/* Structure of one note record */
typedef struct /* Each note record is 715 bytes long */
{
int received; /* 0 if not read, else 1 */
char extra1[16]; /* mail code, else 0 */
char extra2[16]; /* mail code2, else 0 */
char extra3[16]; /* mail code3, else 0 */
char header[165]; /* top line of text and border */
char body[500]; /* body of message */
} note_rec;
/* Sample C Function to write a proper DogWorld note record */
/* Note that in most cases you will not want these notes displayed after */
/* your IGM returns to DogWorld. You will only want the codes to be */
/* processed. In this case you should use the invisible note marker (``) */
/* double back-quote for both the title and body of your note. */
/* note. Example: WriteNote("``", "``", `G100, "", ""); */
/* This adds 100 bones to player, simulating direct access to data file */
void WriteNote(char *title, /* Title of note */
char *body, /* Body of note */
char *code1, /* First code [optional] */
char *code2, /* Second code [optional] */
char *code3); /* Third code [optional] */
FILE *AppendShareFile(char *FileName, char *FileMode, int *FileHandle);
void CloseExclusiveShareFile(FILE *pFile, int FileHandle);
void WriteNote(char *title, char *body, char *code1, char *code2, char *code3)
{
char HeadHold[164], NoteFilename[81], NoteFileHold[10];
FILE *nfile; int hnote;
note_rec tnote;
/* The path to DogWorld is stored in the global variable DogPath */
/* Setup your IGM to retreive this path from an external data file. */
/* Player record # (shown as 'record') is read from the INFO.x file. */
/* Put together complete path and name of the NOTE.x file */
strcpy(NoteFilename, DogPath);
sprintf(NoteFileHold,"NOTE.%d", record);
strcat(NoteFilename, NoteFileHold);
trim(NoteFilename);
NoteFileHold[0]='\0';
tnote.received=0; /* <--- Always set this to zero! */
/* Put together the note title, including border */
strcpy(HeadHold, title);
strcat(HeadHold, "`n`@---:---:---:---:---:---:---:---:---:---:---:---:---`n");
strncpy(tnote.header, HeadHold, 165);
/* Setup the body of the note */
strncpy(tnote.body,body,500);
/* Setup the code fields */
strncpy(tnote.extra1,code1,16);
strncpy(tnote.extra2,code2,16);
strncpy(tnote.extra3,code3,16);
/* Attempt to open the NOTE.x file. If success, append the new record */
if((nfile=AppendShareFile(NoteFilename, "ab", &hnote))==NULL)
{
od_printf("Can't open file: %s.", NoteFilename);
}
else
{
fseek(nfile, 0L, SEEK_END);
fwrite(&tnote, 1, sizeof(note_rec), nfile);
CloseExclusiveShareFile(nfile, hnote);
}
}
/* Function to do exclusive file open */
#include <share.h>
#include <sys\stat.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <time.h> /* for struct tm */
#include <io.h>
#define WAIT_FOR_FILE 20
FILE *AppendShareFile(char *FileName, char *FileMode, int *FileHandle)
{
if(multi_node) /* Get multi_node value from INFO.x (line 32) */
{
FILE *fpFile = NULL;
time_t StartTime = time(NULL);
int hFile;
while((hFile = sopen(FileName,O_BINARY|O_APPEND|O_CREAT|O_RDWR,
SH_DENYRW,S_IREAD|S_IWRITE)) == -1)
{
if(errno != EACCES ||
difftime(time(NULL), StartTime) >= WAIT_FOR_FILE)
break;
od_kernel(); /* If using OpenDoors call od_kernel to */
} /* keep things updated. */
if(hFile != -1)
{
fpFile = fdopen(hFile, FileMode);
if(fpFile == NULL)
{
close(hFile);
}
}
*FileHandle = hFile;
return(fpFile);
}
else
{
(void)FileHandle;
return(fopen(FileName, FileMode));
}
}
void CloseExclusiveShareFile(FILE *pFile, int FileHandle)
{
fclose(pFile);
if(multi_node) /* <---- Get from info.x */
close(FileHandle);
else
(void)FileHandle;
}